package com.bruce.tool.map.baidu.web.to;

import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;

import java.io.Serializable;

/**
 * @author 刘正航
 * @version 2021/1/1
 */
@Data
public class ReverseAddress implements Serializable {

    private AddressInfo addressComponent;
    @JSONField(name = "formatted_address")
    private String formattedAddress;

    @Data
    static class AddressInfo implements Serializable {
        private String province;
        private String city;
        private String district;
    }

    public Address toAddress() {
        return Address.builder()
                .province(this.addressComponent.getProvince())
                .city(this.addressComponent.getCity())
                .district(this.addressComponent.getDistrict())
                .address(this.formattedAddress)
                .build();
    }
}
